﻿/*Author：Lary Pan(itolmqj123@gmail.com)
 *Date  ：2016/6/5
 *Tips  ：Tips提示信息管理器
 * */
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TipsManager : UnitySingleton<TipsManager>, IManager
{
	private Queue<string> tipsQueue;
	private bool canTip = true;
    private float tipDur = 1f;

	public void Init()
	{
		tipsQueue = new Queue<string>();
		canTip = true;
	}
	
	public void DoDestroy()
	{
		tipsQueue = null;
	}

    private void Update()
    {
        if (canTip)
        {
            if (tipsQueue.Count > 0)
            {
                ShowTips(tipsQueue.Dequeue());
            }
        }
    }

    private void _CreateTips(string txt)
	{
		canTip = false;
		ResHelper.LoadLocalRes(GlobleConfig.ResPath.UITip, (_obj) => {
			GameObject obj = _obj as GameObject;
			UITip tip = obj.GetComponent<UITip>();
			if (tip)
			{
                tip.destroyTime = tipDur;
				tip.Show(txt, OnTipClose);
			}
		});
	}

    private void OnTipClose()
    {
        Debug.Log("tip close");
        canTip = true;
    }

	public void ShowTips(string txt, params object[] param)
	{
		if (param.Length > 0)
		 	txt = string.Format(txt, param);
		_CreateTips(txt);
	
	}
	
}
